package com.zhang.zhangapp.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhang.zhangapp.R;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/4/26.
 */

public class FilterAdapter extends BaseAdapter {
    List<Map<String, String>> filters;
    Context context;

    public FilterAdapter(List<Map<String, String>> filters, Context context) {
        this.filters = filters;
        this.context = context;
    }

    @Override
    public int getCount() {
        return filters == null ? 0 : filters.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        view = LayoutInflater.from(context).inflate(R.layout.item_filter,null);
        TextView textView = view.findViewById(R.id.text);
        ImageView imageView = view.findViewById(R.id.imageview);
        Map<String,String> map = filters.get(i);
        if(map.containsKey("selected") && map.get("selected").equals("true")){
            textView.setSelected(true);
            imageView.setVisibility(View.VISIBLE);
        }else {
            textView.setSelected(false);
            imageView.setVisibility(View.GONE);
        }
        textView.setText(map.get("label"));
        return view;
    }
}
